﻿using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;
using UnityEngine;
using System.Net;

using System.Text.RegularExpressions;
using UnityEngine.SceneManagement;

public class Utils{



	public static void checkIsInRoom(){
		if (Main.room == null || Main.room.players.Count == 0) {
			return;
		}
		checkRoomInfo ("{\"player_number\":" + Main.room.playerNum + "}");
	}

	//检测用户在哪个场次
	public static bool checkRoomInfo(object obj){
		JSONObject json = JSONObject.Create (obj.ToString());
		//人数场次
		if (json ["player_number"].IsNumber) {
			int playerNumber = int.Parse (json ["player_number"].ToString ());
			switch (playerNumber){
			case 2:
				LoadScene ("P2");
				break;
			case 3:
				LoadScene ("P3");
				break;
			case 4:
				LoadScene ("P4");
				break;
			case 5:
				LoadScene ("P5");
				break;
			case 6:
				LoadScene ("P6");
				break;
			}
			return true;
		}
		return false;
	}

	public static void LoadScene(string targetScene){
		if (SceneManager.GetActiveScene ().name == targetScene) {
			return;
		}
		SceneManager.LoadScene (targetScene);
	}

}

class CardComparer:IComparer<string>{
	public int Compare(string x, string y) {
		if (x.Contains ("大") || x.Contains ("小") ) {
			x = x.Contains ("大") ? "17_17" : "16_16";
		}
		if (y.Contains ("大") || y.Contains ("小") ) {
			y = y.Contains ("大") ? "17_17" : "16_16";
		}

		string xString = x.Split ('_') [1];
		string yString = y.Split ('_') [1];

		int xValue = int.Parse(xString == "A" ? "14" : xString == "J"?"11":xString == "Q" ? "12" : xString == "K" ? "13":xString);
		int yValue = int.Parse(yString == "A" ? "14" : yString == "J"?"11":yString == "Q" ? "12" : yString == "K" ? "13":yString);
//		Debug.Log (xValue.ToString() + ":" + yValue.ToString() + "result:"+xValue.CompareTo (yValue).ToString());
		return xValue.CompareTo (yValue);
	}
}
		